package com.china08.yxyapi.api.manage.tec.office.stuattendance;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import com.china08.yxyapi.api.YxyApiBaseController;
import com.china08.yxyapi.model.YxyApiReqModel;
import com.china08.yxyapi.model.YxyApiRespModel;
import com.china08.yxyapi.service.manage.tec.stuattendance.impl.YxyStuAttendanceServiceImpl;

/**
 * 导出所查询学生考勤记录
 * 
 */
@CrossOrigin
@RestController
public class YxyStuAttendanceRecordDownloadController extends YxyApiBaseController {
    @Autowired
    public YxyStuAttendanceServiceImpl yxyStuAttendanceServiceImpl;

    @RequestMapping(value = "/api_yw/manage/tec/office/stuattendance/record/download", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_UTF8_VALUE)
    public Map<String, Object> precess(HttpServletRequest request, HttpServletResponse response,
            @RequestBody ReqModel model) throws Exception {
        List<Map<String, String>> returnMap = yxyStuAttendanceServiceImpl.getStuAttendanceForDownload(
                getProfile(request, response).getSchoolId(), model.classId,
                Integer.parseInt(model.month.substring(0, 4) + "" + model.month.substring(5)), model.signClass,
                model.keyWord);
        // 班级名称
        String classNike = null;
        // 导入excal所需数据
        Map<String, Object> dataMap = new HashMap<String, Object>();
        // 循环所需数据
        List<Map<String, String>> list = new ArrayList<Map<String, String>>();
        for (Map<String, String> mapList : returnMap) {
            if (classNike == null) {
                classNike = mapList.get("className");
            }
            list.add(mapList);
        }
        dataMap.put("classNike", classNike);
        dataMap.put("list", list);
        dataMap.put("size", String.valueOf(list.size() + 2));
        return dataMap;
    }

    /**
     * 请求参数
     * 
     */
    protected static class ReqModel extends YxyApiReqModel {
        // 班级id
        public String classId;
        // 月份
        public String month;
        // 到班状态
        public String signClass;
        // 输入参数
        public String keyWord;
    }

    /**
     * 响应参数
     * 
     */
    protected static class RespModel extends YxyApiRespModel {
        public long count;
        // id
        public String id;
        // 编号
        public String index;
        // 日期
        public String date;
        // 学生姓名
        public String stuName;
        // 学号
        public String stuNo;
        // 班级
        public String className;
        // 到校时间
        public String signInDate;
        // 离校时间
        public String signOutDate;
        // 晨检状态
        public String inspection;
        // 晨检时间
        public String inspectionDate;
        // 到班状态
        public String signClass;
        // 到班时间
        public String signClassDate;
    }
}
